import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import GoodsView from "@/views/userView/GoodsView.vue";
import HomeView from "@/views/userView/HomeView.vue";
import GroupView from "@/views/userView/GroupView.vue";
import UserOrder from "@/views/userView/UserOrder.vue";
import UserLogin from "@/views/userView/UserLogin.vue";
import SellerView from "@/views/sellerView/SellerView.vue";
import UserRegister from "@/views/userView/UserRegister.vue";
import SellerGoods from "@/views/sellerView/SellerGoods.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/user/home",
    name: "userHome",
    component: HomeView,
  },
  {
    path: "/user/goods",
    name: "userGoods",
    component: GoodsView,
  },
  {
    path: "/user/goods/detail/:id",
    name: "goodsDetail",
    component: () => import("@/views/goods/GoodsView.vue"),
  },
  {
    path: "/user/group",
    name: "userGroup",
    component: GroupView,
  },
  {
    path: "/user/order",
    name: "userOrder",
    component: UserOrder,
  },
  {
    path: "/user/Login",
    name: "userLogin",
    component: UserLogin,
  },
  {
    path: "/user/register",
    name: "userRegister",
    component: UserRegister,
  },
  {
    path: "/seller",
    name: "sellerView",
    component: SellerView,
    children: [
      // 子路由路径不要以 / 开头
      {
        path: "goods", // 完整路径会自动拼接为 /seller/goods
        name: "sellerGoods",
        component: SellerGoods,
      },
      {
        path: "order",
        name: "sellerOrder",
        component: () => import("@/views/sellerView/SellerOrderView.vue"),
      },
    ],
  },
  {
    path: "/admin",
    name: "adminView",
    component: () => import("@/views/adminView/AdminHome.vue"),
    children: [
      {
        path: "goods",
        name: "adminGoods",
        component: () => import("@/views/adminView/goodsView.vue"),
      },
      {
        path: "order",
        name: "adminOrder",
        component: () => import("@/views/adminView/OrderView.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
